//package org.jeecg.modules.zhima.base.shiro.filter;
//
//import com.baomidou.mybatisplus.core.toolkit.StringUtils;
//import lombok.extern.slf4j.Slf4j;
//import org.jeecg.modules.zhima.base.shiro.service.TokenService;
//import org.jeecg.modules.zhima.portal.config.authc.vo.DefContants;
//import org.jeecg.modules.zhima.portal.domain.WXMemberDetails;
//import org.jeecg.modules.zhima.portal.service.IUserService;
//import org.jeecg.modules.zhima.portal.util.JwtTokenUtil;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.core.Ordered;
//import org.springframework.core.annotation.Order;
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
//import org.springframework.security.core.context.SecurityContextHolder;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.*;
//import javax.servlet.http.HttpServletRequest;
//import java.io.IOException;
//
///**
// * @Description: 鉴权登录拦截器
// * @Author: Scott
// * @Date: 2018/10/7
// **/
//@Slf4j
//@Order(Ordered.HIGHEST_PRECEDENCE)
//@Component
//public class JwtTokenFilter implements Filter {
//
//	@Autowired
//	private TokenService jwtTokenUtil;
//	@Autowired
//	private IUserService userService;
//
//	@Override
//	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//		HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
//		String token = httpServletRequest.getHeader(DefContants.X_ACCESS_TOKEN);
//		if (StringUtils.isBlank(token)) {
//			log.info("filter token is null");
////			throw new AuthenticationException("token is null");
//			filterChain.doFilter(servletRequest, servletResponse);
//			return;
//		}
//		String type = jwtTokenUtil.getType(token);
//		String username = jwtTokenUtil.getWxOpenId(token);
//		if (StringUtils.isBlank(username)) {
//			log.info("token非法无效!");
//			filterChain.doFilter(servletRequest, servletResponse);
//			return;
//		}
//		WXMemberDetails userDetails = userService.getUserDetails(username);
//		if (userDetails.getUmsMember() == null) {
//			log.info("用户不存在!");
//			filterChain.doFilter(servletRequest, servletResponse);
//			return;
//		}
//		UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
//		log.debug("authenticated user:{}", username);
//		SecurityContextHolder.getContext().setAuthentication(authentication);
//		filterChain.doFilter(servletRequest, servletResponse);
//	}
//}
